<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>vaeThink</title>
  {include file="../common/header"}
</head>
<body class="vae-body">

<div class="vae-content">
  <form class="layui-form" style="display: inline;">
    <input type="text" name="keywords" required  lay-verify="required" placeholder="ID/名称/描述" class="layui-input" autocomplete="off" style="max-width: 200px;display: inline;margin: -10px 10px 0 0;height: 30px;" />
    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-submit="" lay-filter="vaeform">提交搜索</button>
  </form> 
  <table class="layui-hide" id="list" lay-filter="test">

  </table>
</div>






{include file="../common/footer"}
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <a class="layui-btn layui-btn-primary layui-btn-sm" href="{:url('sms/add')}">添加短信</a>
  </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-normal layui-btn-xs" href="/voip/sms/updateSms/id/{{d.id}}" lay-event="update">编辑</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="status">状态切换</a>

</script>
<script>
layui.config({
    base: '/themes/admin_themes/module/'
}).use(['table','vaeyo','form'], function(){
  var table = layui.table
  ,vae = layui.vaeyo
  ,$ = layui.$
  ,form = layui.form;
  
  var tableIns = table.render({
    elem: '#list'
    ,toolbar: '#toolbarDemo'
    ,url: "{:url('sms/ajaxGetSms')}" //数据接口
    ,page: true //开启分页
    ,limit: 15
    ,cols: [[ //表头
      {field: 'id', title: '序号', sort: true, fixed: 'left', align:'center', width:80}
      ,{field: 'title', title:'短信名字',  align:'center'}
      ,{field: 'signame', title: '短信头部', align:'center'}
      ,{field: 'codenumber', title:'阿里云模板ID',  align:'center'}
      ,{field: 'data', title:'短信填写值',  align:'center'}
      ,{field: 'intro', title:'短信简介',  align:'center'}
      ,{field: 'name', title:'短信类别',  align:'center'}
      ,{field: 'create_time', title:'创建时间',  align:'center'}
      ,{field: 'status', title:'状态',  align:'center'}
      ,{field: 'uniqid', title:'唯一编码',  align:'center',width:250 }
      ,{field: 'right', toolbar: '#barDemo', title:'操作',width:150, align:'center'}

    ]]
  });
  
  //监听行工具事件
  table.on('tool(test)', function(obj){
    var data = obj.data;
    //console.log(obj)
    var tr=obj.tr.selector;

    var index1=tr.replace(/[^0-9]/g, "");//price值为：200
    index1++;
    if(obj.event === 'status'){
      var isName=$("tr:eq("+index1+")").find("td:eq(8)").find('div').text();

      var typename;
      switch (isName) {
        case '正常':
          typename='禁用';
          break;
        case '禁用':
          typename='正常';
          break;
      }
      layer.confirm('切换状态吗', {icon: 3, title:'提示'}, function(index){
        $.ajax({
          url:"/voip/sms/updateSmsStatus",
          data:{id:data.id,status:isName},
          success:function(res){
            layer.msg(res.msg);
            if(res.code==1){
              $("tr:eq("+index1+")").find("td:eq(8)").find('div').html(typename);
            }
          }
        })
        layer.close(index);
      });
    }
  });

  //监听搜索提交
  form.on('submit(vaeform)', function(data){
    console.log(data.field.keywords)
    if(data.field.keywords) {
      tableIns.reload({where:{keywords:data.field.keywords}});
      vae.bundledTab();
    }
    return false;
  });
});
</script>

</body>
</html>